#include "framelesswindow.h"
#include "ui_framelesswindow.h"

FramelessWindow::FramelessWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FramelessWindow)
{
    ui->setupUi(this);

    // 设置窗口为无边框
    setWindowFlags(Qt::FramelessWindowHint);
}

FramelessWindow::~FramelessWindow()
{
    delete ui;
}

void FramelessWindow::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        // 记录鼠标按下的位置
        dragPosition = event->pos();
        isDragging = true;
    }
}

void FramelessWindow::mouseMoveEvent(QMouseEvent *event)
{
    if (isDragging && (event->buttons() & Qt::LeftButton)) {
        // 计算窗口的新位置
        int dx = event->x() - dragPosition.x();
        int dy = event->y() - dragPosition.y();
        move(x() + dx, y() + dy);
    }
}

void FramelessWindow::mouseReleaseEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        isDragging = false;
    }
}

void FramelessWindow::on_btn_close_clicked()
{
    this->close();
}


void FramelessWindow::on_btn_min_clicked()
{
    this->showMinimized();
}

